"""
tuple_nested_unpacking.py

Demonstration of nested tuple unpacking::

    >>> main()
                    |  latitude | longitude
    Mexico City     |   19.4333 |  -99.1333
    New York-Newark |   40.8086 |  -74.0204
    São Paulo       |  -23.5478 |  -46.6358

"""

# tag::MAIN[]
metro_areas = [
    ('Mexico City', 'MX', 20.142, (19.433333, -99.133333)),
    ('New York-Newark', 'US', 20.104, (40.808611, -74.020386)),
    ('São Paulo', 'BR', 19.649, (-23.547778, -46.635833)),
]

def main():
    print(f'{"":15} | {"latitude":>9} | {"longitude":>9}')
    # (lat, lon)是重点！
    for name, _, _, (lat, lon) in metro_areas:  # 可以加括号：for (name, _, _, (lat, lon)) in metro_areas
        if lon <= 0:
            print(f'{name:15} | {lat:9.4f} | {lon:9.4f}')
    # 按对应的数据结构书写左侧，就能直接提取元素


def main2():
    for name, _, _, t in metro_areas:
        print(name, t)
    # 将()看作整体，也行
    [[nest]] = [[1]]  # 也可以展开list，多用于已知必定为单结果的SQL
    print(nest)


if __name__ == '__main__':
    main()
    main2()
# end::MAIN[]